package sg.techstudio.suntec.main;

import java.io.Serializable;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import sg.techstudio.suntec.dao.RadiusDao;

@Component
public class ClearMacAddressMain implements Serializable{
	private static final long serialVersionUID = 6946357998830569995L;
	private static final Log log = LogFactory.getLog(ClearMacAddressMain.class);
	protected static String configLocation = "config/spring-context.xml";
	
	@Autowired
	private RadiusDao radiusDao;
	
	private static ClearMacAddressMain clearMacAddressMain;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		log.debug("start");
		
		try {
			if(args!=null && args.length>=1)
				configLocation = args[0];
			
			initProcess();
			clearMacAddressMain.mainProcess();
			
		} catch(Exception e) {
			log.error("Exception at main():"+e, e);
		}
		
		log.debug("end");
	}
	
	@SuppressWarnings("resource")
	private static void initProcess() {
		log.debug("initProcess() entry");
		ApplicationContext ctx = new ClassPathXmlApplicationContext(configLocation);
		clearMacAddressMain = ctx.getBean(ClearMacAddressMain.class);
	}
	
	private void mainProcess(){
		log.debug("mainProcess() entry");
		radiusDao.clearOldMacSession();
		log.debug("mainProcess() exit");
	}

}
